﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>

<script runat="server">
    
    private int ca_id;
    private string c_dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        string c_dt = null;
        if (Request.QueryString["c_dt"] != null)
        {
            c_dt = Request.QueryString["c_dt"];
            this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;
        }
        else
        {
            c_dt = DateTime.Now.ToShortDateString().Replace("-", "/");
            this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;
        }
        
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["ca_id"] != null && Request.QueryString["c_dt"] != null)
            {
                ca_id = int.Parse(Request.QueryString["ca_id"]);
                c_dt = Request.QueryString["c_dt"];
                this.LblCurDate.Text = "(" + c_dt + ")";
                UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
                UserCalendarArrangetb ucatb = ucatbService.findByCaId(ca_id);
                if (ucatb != null)
                {
                    this.TxtTitle.Text = ucatb.CalendarArrangeTitle;
                    this.TxtContent.Text = ucatb.CalendarArrangeContent;
                    this.TxtStart.Text = ucatb.CalendarArrangeStartTime;
                    this.TxtEnd.Text = ucatb.CalendarArrangeEndTime;
                    this.IntervalMinute.Text = ucatb.CalendarArrangeIntervalMinute.ToString();
                    
                    string type = ucatb.CalendarArrangeType.Trim();
                    for (int i = 0; i < this.selectCalType.Items.Count; i++)
                    {
                        if (type.Equals(this.selectCalType.Items[i].Value))
                        {
                            this.selectCalType.Items[i].Selected = true; 
                        }   
                    }  
                }
                ViewState["ca_id"] = ca_id;
                ViewState["c_dt"] = c_dt;
            }   
        }  
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ViewState["ca_id"] != null && ViewState["c_dt"] != null)
        {
            ca_id = (int)ViewState["ca_id"];
            c_dt = (string)ViewState["c_dt"];  
        }  
        string calendarTitle = Request.Form.Get(this.TxtTitle.ClientID);
        string calendarContent = Request.Form.Get(this.TxtContent.ClientID);
        string startTime = TxtStart.Text;
        string endTime = TxtEnd.Text;
        int intervalMinute = int.Parse(this.IntervalMinute.Text);
        string type = Request.Form.GetValues(this.selectCalType.ClientID)[0];
        UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
        if (ucatbService.UpdateCalendarArrangeInfoById(ca_id, calendarTitle, calendarContent, startTime, endTime, intervalMinute,
            type) == true)
        {
            User curLoginUser = (User)Session["user"]; 
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('事务更新成功！');", true);
             CalendarArrangeInfos cainfos = CalendarArrangeInfos.instance();
             List<UserCalendarArrangetb> list = (List<UserCalendarArrangetb>)cainfos.Cainfos[curLoginUser.LoginName];
             if (list != null)
             {
                 if (list.Count > 0)
                 {
                     for (int i = 0; i < list.Count; i++)
                     {
                         UserCalendarArrangetb ucatb = list[i];
                         if (ucatb.CalendarArrangeId == ca_id)
                         {
                             list.Remove(ucatb);
                             i--; 
                         }
                     } 
                 }
                 list.Add(ucatbService.findByCaId(ca_id)); 
             }    
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('事务更新失败！');", true);
        }
        ViewState["ca_id"] = ca_id;
        ViewState["c_dt"] = c_dt;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ViewState["ca_id"] != null && ViewState["c_dt"] != null)
        {
            ca_id = (int)ViewState["ca_id"];
            c_dt = (string)ViewState["c_dt"];
        }  
        Response.Redirect("CalendarArrangeShow.aspx?c_dt=" + c_dt);
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    
    <link rel="Stylesheet" type="text/css" href="../Styles/right_style.css" />

    
   <script type="text/javascript" src="../Scripts/jquery.ui/js/jquery.js"></script>
   <script type="text/javascript" src="../Scripts/My97DatePicker/WdatePicker.js"></script>
 
   <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>
 <script type="text/javascript">
     function validateForm() {
         var title = $("#TxtTitle");
         var startTime = $("#TxtStart");
         var endTime = $("#TxtEnd");
         var interval = $("#IntervalMinute");
         var content = $("#TxtContent");

         var flag = true;

         if (title.val() == '') {
             alert("标题不能为空");
             flag = false;
         } else if (startTime.val() == '') {
             alert("开始时间不能为空");
             flag = false;
         } else if (endTime.val() == '') {
             alert("结束时间不能为空");
             flag = false;
         } else if (interval.val() == '') {
             alert("时间间隔不能为空");
             flag = false;
         } else if (content.val() == '') {
             alert("事务内容不能为空");
             flag = false;
         }
         return flag;
     }
    </script>
        
</head>
<body>
    <form id="form1" runat="server">
    <div  class="sub_right_top">
            <!--滑动门-->
    <div class="hdm_header" >
     <div class="tb1_off" id="tab1"><h2 class="h2_icon">
     <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/CalendarArrange/ArrangeIndex.aspx">日程安排</asp:HyperLink>
     </h2></div>
     <div class="tb1_off" id="tab2"><h2 class="h2_icon">
      <asp:HyperLink ID="HyperLink2" runat="server">今日日程</asp:HyperLink>
     </h2></div>
      <div class="tb1_off" id="tab3"><h2 class="h2_icon">
            <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/CalendarArrange/CalendarArrangeDemand.aspx">日程查询</asp:HyperLink>
      </h2></div>
     <div class="clear"></div>
   </div>
   <div class="hdm_footer">
   <div id="tb1_2_content" class="cont01_word" style="display:block;">     
        <div class="fabu_gg_title">&nbsp;编辑事务<asp:Label
                        ID="LblCurDate" runat="server" Width="223px"></asp:Label></div>    
        <table width="96%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0" style="border-collapse:collapse; ">
            <tr bgcolor="#e4f1fd">
           <td colspan="2" align="center"><strong>编辑事务信息</strong></td>
          </tr>
            <tr>
           <td width="100">事务标题：</td>
           <td>
             <asp:TextBox ID="TxtTitle" runat="server" Width="377px" dojotype="dijit.form.TextBox"></asp:TextBox>
           </td>
         </tr>
         <tr>
         <td width="100">开始时间：</td>
           <td><asp:TextBox ID="TxtStart" runat="server"  CssClass="Wdate" onClick="WdatePicker({dateFmt:'HH:mm'})"></asp:TextBox></td>
        </tr>
        <tr>
           <td width="100">结束时间：</td>
           <td><asp:TextBox ID="TxtEnd" runat="server"  CssClass="Wdate" onClick="WdatePicker({dateFmt:'HH:mm'})"></asp:TextBox></td>
        </tr>
        <tr>
           <td width="100">提醒间隔：</td>
           <td><asp:TextBox ID="IntervalMinute" runat="server"  CssClass="Wdate" onClick="WdatePicker({dateFmt:'mm'})"></asp:TextBox></td>
           </tr>
           <tr>
               <td width="100">事务类型：</td>
               <td>
                    <select id="selectCalType" runat="server" class="BigSelect" name="selectCalType" style="width:140px;"> 
                        <option value="1">工作事务</option>
                        <option value="2">个人事务</option>
                    </select>
               </td>
         </tr>
         <tr>
         <td width="100" valign="top">事务内容：</td>
           <td><asp:TextBox ID="TxtContent" runat="server" Height="140px" TextMode="MultiLine" Width="100%" Font-Size="12px"></asp:TextBox></td>
         </tr>
          <tr>
           <td width="100">&nbsp;</td>
           <td><div class="disk_queding_top">
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="确定" OnClientClick="return validateForm();"/>
           </div>
          <div class="disk_back_top">
            <input type="button" id="Button2" onclick="window.history.back();"  value="" class="fanhui_anniu"/>
          </div> </td>
         </tr>
        </table>
     </div>
    </div>
    </div>
    </form>
</body>
</html>
